package cn.tedu.boot42.mapper;

import cn.tedu.boot42.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    //把从数据库请求到的用户集合返回给客户端
    //如果给客户端返回的内容为数值或字符串，服务器会直接返回给客户端
    //但如果返回的内容类型为对象或集合,SpringMVC框架会将对象或集合中的数据装进Json格式的字符串中,再返回给客户端

    @Select("select * from user")
    List<User> findAll();

    @Select("select count(*) from user where binary username=#{username} and binary password=#{password}")
    int findUserByUP(String username, String password);

    @Select("select count(*) from user where binary username=#{username}")
    int findUserByUsername(String username);

    @Insert("insert into user values(null,#{username},#{password},#{nick},#{age})")
    int insertUser(User user);

    @Update("update user set username=#{username},password=#{password},nick=#{nick},age=#{age} where id=#{id}")
    int updateUserById(User user);

    @Delete("delete from user where id=#{id}")
    int deleteUserById(Integer id);

}
